package com.hejjon.visualization.controller;

import com.alibaba.fastjson.JSONObject;
import com.hejjon.visualization.bean.ResponseResult;
import com.hejjon.visualization.entity.XUser;
import com.hejjon.visualization.service.IUserService;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created by caoshi at 4:55 2021-09-14
 */
@RestController
public class LoginController {

    private static Logger logger = LoggerFactory.getLogger(LoginController.class);

    @Autowired
    private IUserService userService;


    @RequestMapping("/login")
    public ResponseResult login(@RequestBody JSONObject loginParam) {
        String username = loginParam.getString("username");
        String password = loginParam.getString("password");
        logger.info("用户登录入参: 用户名: {}, 密码: {}", username, password);
        if (StringUtils.isEmpty(username) || StringUtils.isEmpty(password)) {
            return new ResponseResult(-1, "error", "error", null);
        }

        XUser user = new XUser();
        user.setUsername(username);
        user.setPassword(password);

        return userService.login(user);
    }


}
